
const baseUrl = 'http://47.100.39.207:9001/'
// const baseUrl = 'dpc/'
export const $request = (url,data,method = 'POST') => {
	let reqUrl = ''
	// console.log(url);
	if (url.indexOf('http://') != -1 || url.indexOf('https://') != -1) {
		reqUrl = url
	} else {
		reqUrl = baseUrl + url
	}
	return new Promise((resolve,reject) => {
		return uni.request({
			url:reqUrl,
			method:method,
			data:data,
			header:{
				token:uni.getStorageSync('token'),
				imei:'df8137dd-d506-e636-122f-eddc0ab3e35d',
				version:'1.0.1',
				client:'web',
				'Content-Type' : 'application/x-www-form-urlencoded'
			},
			success(res) {
				if(res.data.code == 0){
					resolve(res)
				}else{
					if (res.data.obj === 'token不合法')  {
						reject(res)
					} else {					
						uni.showToast({
							title:res.data.obj,
							icon:'none'
						})
					}
				}
				
			},
			fail(err) {
				reject(err)
			}
		})
	})
}